/******************************************/
/******************************************/
/****  JS Document                     ****/
/****  type/code 2010                  ****/
/****  by Andrew Mahon                 ****/
/******************************************/
/******************************************/

(function(tc) {
	tc.jQ.fn.blogHeader = function(options){
		var $tcbh = this, _o = {}, _isOpen = true, _top = true, _scrollLocked = true
		
		_o = tc.jQ.extend({
			
		},options)
		
		function _initialize(){
			tc.util.log("type/code Blog Header Starting",'info')
			if(tc.jQ(document).scrollTop() < 5){
				_top = true
			} else {
				_top = false
			}
			_setup_events()
			return $tcbh
		}
		
		function _setup_events(){
			tc.jQ('#container').unbind('mousemove').bind('mousemove',_mousemoveEventHandler)
			tc.jQ('#container').unbind('mouseout').bind('mouseout',_mouseoutEventHandler)
			tc.jQ(document).unbind('scroll').bind('scroll',_scrollEventHandler)
		}
		
		function _mousemoveEventHandler(e){
			if(e.clientY < 50 && !_isOpen && !_top){
				_appear()
			} else if(e.clientY > 50 && _isOpen && !_top){
				_dissapear()
			}
		}
		
		function _mouseoutEventHandler(e){
			//_dissapear()
		}
		
		function _scrollEventHandler(){
			if(tc.jQ(document).scrollTop() < 5){
				_top = true
				_isOpen = false
				$tcbh.stop().css('position','absolute')
						.css('top','0px')
			} else {
				_top = false
			}
		}
		
		function _appear(){
			_isOpen = true
			$tcbh.stop().css('top','-34px')
				.css('position','fixed')
				.animate({'top':'0px'},600)
		}
		
		function _dissapear(){
			_isOpen = false
			$tcbh.stop().animate({'top':'-34px'},600,function(){
				tc.jQ(this).css('position','absolute')
					.css('top','0px')
			})
		}
		
		
		
		return _initialize()
	}
})(tc);